package oocl.eshop.ui.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import oocl.eshop.po.Food;
import oocl.eshop.po.Merchant;
import oocl.eshop.service.FoodManager;
import oocl.eshop.service.impl.FoodManagerImpl;

/**
 * Servlet implementation class ShowFoodPageServlet
 */
public class ShowFoodPageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	FoodManager foodManager = new FoodManagerImpl();

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ShowFoodPageServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
		Merchant merchant = (Merchant) session.getAttribute("merchant");
		int mId = merchant.getmId();
		System.out.println(mId);
		
		if (session.getAttribute("foods") == null) {
			session.setAttribute("foods", foodManager.findFoodBymid(mId));
		}
		List<Food> foods = foodManager.findFoodBymid(mId);
		System.out.println("food:"+foods.size());
		for(Food f:foods){
		System.out.println(f.getfViewPath());
		}
		response.sendRedirect("menuPage.jsp");

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
